<!DOCTYPE html>
<html lang="zh_CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0">
  <title>Title</title>
</head>
<body>
<script>
  if ('serviceWorker' in navigator) {
    window.addEventListener('load', function () {
      navigator.serviceWorker.register('./sw.js', {scope: '/demo/ServiceWorker/'})
      .then(function (registration) {

        // 注册成功
        console.log('ServiceWorker registration successful with scope: ', registration.scope);
      })
      .catch(function (err) {

        // 注册失败:(
        console.log('ServiceWorker registration failed: ', err);
      });
    });
  }
</script>
</body>
</html>
